import 'dart:convert';
import 'package:base_lib/common/network/net.dart';
import 'package:base_lib/common/network/result_body.dart';
import 'package:base_lib/config.dart';
import 'doctor_net_intercept.dart';
import '../prescription/entity/prescription_order_list_entity.dart'
    as OrderListBean;
import '../prescription/entity/get_person_info_by_ids_entity.dart'
    as PersonInfoBean;
import '../prescription/entity/rp_detail_entity.dart' as RpDetailBean;
import '../prescription/entity/prescription_order_info_entity.dart'
    as OrderInfoBean;
import '../prescription/entity/get_medicine_info_entity.dart'
    as MedicineInfoBean;

///处方相关网络请求
class DoctorOrderHttp {
  /// 处方订单列表
  static const INTERFACE_INQUIRY_ORDER_GET =
      "api/medicine/goodsOrder/getOrderForDoctorByPage";

  /// 批量获取头像
  static const INTERFACE_GET_PERSON_INFO_BY_PERSON_ID_LIST =
      "api/peachUser/personUser/getPersonInfoByPersonIDList";

  /// 获取处方笺信息
  static const PHARMACY_GET_PAY_ORDER_RP_DATA =
      "api/rp/prescription/getRpDetail";

  /// 查询药品、处方订单详情
  static const PHARMACY_GET_ORDER_MEDICINE_OR_RP =
      "api/medicine/goodsOrder/getOrderInfo";

  /// 根据药品ID集合批量查询药品基本信息
  static const PHARMACY_POST_PAY_ORDER_GOODS_INFO_DETAILS =
      "api/medicine/medicineProduct/getMedicineInfoByList";

  /// 根据药品ID集合批量查询药品图片
  static const PHARMACY_POST_PAY_ORDER_GOODS_INFO_IMAGES =
      "api/medicine/medicineProduct/getMedicineImgByList";

  static HttpManager _httpProxyIns;

  static createHttpProxy(
      {mBaseUrl = Config.doctorBaseUrl,
      codeName = Config.codeName,
      codeSuccessValue = Config.codeSuccessValue,
      msgName = Config.msgName,
      reqTimeOut = Config.reqTimeOut,
      respTimeOut = Config.respTimeOut,
      logTag = "login"}) {
    _httpProxyIns = HttpManager(mBaseUrl,
        CODE_NAME: codeName,
        CODE_SUCCESS_VALUE: codeSuccessValue,
        MSG_NAME: msgName,
        REQ_TIME_OUT: reqTimeOut,
        RESP_TIME_OUT: respTimeOut,
        LOG_TAG: logTag,
        defaultInterceptors: [DoctorOrderIntercept()]);
  }

  ///处方订单列表
  static Future<ResultBody<OrderListBean.Data>> getPrescriptionOrder(
      pageIndex, doctorID, date,
      {pageSize = 10}) {
    return _httpProxyIns.get<OrderListBean.Data>(INTERFACE_INQUIRY_ORDER_GET,
        (resMap) {
      return OrderListBean.PrescriptionOrderListEntity.fromJson(resMap).data;
    },
        // let data = {
        // pageSize: this.pageInfo.pageSize,
        // pageIndex: this.pageInfo.pageIndex,
        // doctorID: this.userInfo.keyID
        // date ： y + "-" + m;
        // };
        queryParams: Map()
          ..["pageSize"] = pageSize
          ..["pageIndex"] = pageIndex
          ..['doctorID'] = doctorID
          ..['date'] = date);
  }

  ///批量获取头像
  static Future<ResultBody<List<PersonInfoBean.Data>>> getUserHeadersByIDs(
      String personsIDsStr) {
    return _httpProxyIns.get<List<PersonInfoBean.Data>>(
        INTERFACE_GET_PERSON_INFO_BY_PERSON_ID_LIST, (resMap) {
      return PersonInfoBean.GetPersonInfoByIDsEntity.fromJson(resMap).data;
    }, queryParams: Map()..["personsID"] = personsIDsStr);
  }

  ///获取处方笺信息
  static Future<ResultBody<RpDetailBean.Data>> getOrderRpDetail(String rpId) {
    return _httpProxyIns.get<RpDetailBean.Data>(PHARMACY_GET_PAY_ORDER_RP_DATA,
        (resMap) {
      return RpDetailBean.RpDetailEntity.fromJson(resMap).data;
    }, queryParams: Map()..["inquiryId"] = rpId);
  }

  ///查询药品、处方订单详情
  static Future<ResultBody<OrderInfoBean.Data>> getOrderMedicineOrRp(
      String orderID) {
    return _httpProxyIns
        .get<OrderInfoBean.Data>(PHARMACY_GET_ORDER_MEDICINE_OR_RP, (resMap) {
      return OrderInfoBean.OrderInfoEntity.fromJson(resMap).data;
    }, queryParams: Map()..["orderID"] = orderID);
  }

  ///根据药品ID集合批量查询药品基本信息
  static Future<ResultBody<List<MedicineInfoBean.Data>>>
      getOrderMedicineInfoDetailsByIds(List<String> ids) {
    return _httpProxyIns.postJson<List<MedicineInfoBean.Data>>(
        PHARMACY_POST_PAY_ORDER_GOODS_INFO_DETAILS, (resMap) {
      return MedicineInfoBean.GetMedicineInfoEntity.fromJson(resMap).data;
    }, jsonData: json.encode(ids));
  }

  ///根据药品ID集合批量查询药品图片
  static Future<ResultBody> getOrderMedicineImages(List<String> ids) {
    return _httpProxyIns.postJson(PHARMACY_POST_PAY_ORDER_GOODS_INFO_IMAGES,
        (resMap) {
      return resMap;
    }, jsonData: json.encode(ids));
  }
}
